home *** CD-ROM | disk | FTP | other *** search
- /**
- GRAB Graph Layout and Browser System
-
- Copyright (c) 1989, Tera Computer Company
- **/
-
- /**
- Implementation of built-in attribute display
- **/
-
- #include "istring.h"
- #include "dview.h"
- #include <InterViews/pattern.h>
- #include <InterViews/event.h>
- #include <InterViews/glue.h>
- #include <InterViews/shape.h>
- #include <InterViews/sensor.h>
- #include <stdio.h>
- #include <string.h>
-
- static char* colorst[numcolor] =
- {
- "black ",
- "gray ",
- "white "
- };
-
- static char* brushst[numbrush] =
- {
- "solid ",
- "bold solid ",
- "dotted ",
- "bold dotted ",
- "dashed ",
- "bold dashed "
- };
-
- static char* shapest[numshape] =
- {
- "rectangle ",
- "circle ",
- "diamond ",
- "oval ",
- "point ",
- "double_box ",
- "error " /* a line shouldn't show up */
- };
-
- static char* no_color_str = "no color ";
- static char* no_brush_str = "no brush ";
- static char* no_shape_str = "no shape ";
-
- DrawView::DrawView (int n)
- /**
- The display consists of a depiction of the 3 attributes and 3 buttons
- to change the values of the attributes
- **/
- {
- size = n;
-
- currentColor = default_color;
- currentBrush = default_brush;
- colorset = false;
- brushset = false;
- shapeset = false;
-
- colorButton = new CycleParam("color", colorString(), this, colort);
- brushButton = new CycleParam("brush", brushString(), this, brusht);
- shapeButton = new CycleParam("shape", shapeString(), this, shapet);
-
- depiction = new Depiction();
-
- Shape *s = depiction->GetShape();
- s->width = size;
- s->height = size/2;
- s->hshrink = 0; /* so the panner can't expand */
- s->hstretch = 0;
- s->vshrink = vfil; /* expanding vertiaclly's's okay */
- s->vstretch = vfil;
- depiction->Reshape(*s);
-
- depiction->painter = new Painter();
- depiction->painter->FillBg(true);
- depiction->painter->SetColors(palette[currentColor], white);
- depiction->painter->SetPattern(solid);
- depiction->painter->SetBrush(brushes[currentBrush]);
- depiction->currShape = default_shape;
-
- Insert(depiction);
- Insert(new VGlue(10, 0, 0));
- Insert(shapeButton);
- Insert(brushButton);
- Insert(colorButton);
- DrawDep ();
- }
-
- /* drawing, redrawing, etc. routines. Must always redraw the depiction */
-
- void DrawView::Draw()
- {
- VBox::Draw();
-
- if (depiction->canvas != nil)
- {
- output->ClearRect(depiction->canvas, 0, 0,
- depiction->xmax, depiction->ymax);
- DrawDep();
- }
- }
-
- void DrawView::Redraw (Coord a, Coord b, Coord c, Coord d)
- {
- Draw();
- }
-
- void DrawView::Update()
- {
- Draw();
- }
-
- void DrawView::Resize ()
- {
- VBox::Resize();
-
- if (depiction->canvas != nil)
- {
- DrawDep();
- }
- }
-
- void DrawView::EraseDep ()
- /* set the colors to white and draw it */
- {
- depiction->painter->SetColors(white, white);
- DrawDep();
- depiction->painter->SetColors(palette[currentColor], white);
- }
-
- void DrawView::DrawDep ()
- {
- depiction->Draw();
- }
-
- char* DrawView::colorString()
- /* return the string representing the current color */
- {
- if (colorset)
- {
- return colorst[currentColor];
- }
- else
- {
- return no_color_str;
- }
- }
-
- char* DrawView::brushString()
- /* return the string representing the current brush */
- {
- if (brushset)
- {
- return brushst[currentBrush];
- }
- else
- {
- return no_brush_str;
- }
- }
-
- char* DrawView::shapeString()
- /* return the string representing the current shape */
- {
- if (shapeset)
- {
- return shapest[depiction->currShape];
- }
- else
- {
- return no_shape_str;
- }
- }
-
- void DrawView::reset(AttType type)
- /**
- reset the attribute of type type to its default value. Called by
- the CycleParam objects
- **/
- {
- EraseDep();
- depiction->inhibit();
- /**
- if we don't do this, each time we change the button text
- the depiction will be redrawn
- **/
-
- switch (type)
- {
- case shapet:
- shapeset = false;
- depiction->currShape = default_shape;
- shapeButton->ChangeText(shapeString());
- break;
-
- case colort:
- colorset = false;
- currentColor = default_color;
- colorButton->ChangeText(colorString());
- depiction->painter->SetColors(palette[currentColor], white);
- break;
-
- case brusht:
- brushset = false;
- currentBrush = default_brush;
- brushButton->ChangeText(brushString());
- depiction->painter->SetBrush(brushes[currentBrush]);
- break;
-
- }
-
- depiction->allow();
- DrawDep();
- }
-
-
- void DrawView::cycle(char* text, boolean forward, AttType type)
- /**
- cycle through the attribute of type type either forward or
- backward. text is the current value of the attribute. Called
- by the CycleParam objects
- **/
- {
- int i;
-
- EraseDep();
- depiction->inhibit();
- /* Don't redraw the depiction when the button text is changed */
-
- switch (type)
- {
- case shapet:
- if (!strcmp(text, no_shape_str)) /* currently no shape */
- {
- shapeset = true;
- depiction->currShape = forward ? rectangle : numshape - 2;
- }
- else /* find the current shape */
- {
- for (i = 0; i < numshape; i++)
- {
- if (!strcmp(shapest[i], text))
- {
- if ((forward && i == numshape - 2) ||
- (!forward && i == rectangle))
- /* changing to noshape */
- {
- depiction->currShape = default_shape;
- shapeset = false;
- }
- else
- {
- depiction->currShape = forward ?
- NextShape(depiction->currShape) :
- PrevShape(depiction->currShape);
- }
-
- break;
- }
- }
- }
-
- shapeButton->ChangeText(shapeString());
- break;
-
- case colort:
- if (!strcmp(text, no_color_str)) /* currently no color */
- {
- colorset = true;
- currentColor = forward ? blackc : numcolor - 1;
- }
- else /* find the current color */
- {
- for (i = 0; i < numcolor; i++)
- {
- if (!strcmp(colorst[i], text))
- {
- if ((forward && i == numcolor - 1) ||
- (!forward && i == blackc))
- /* changing to no color */
- {
- currentColor = default_color;
- colorset = false;
- }
- else
- {
- currentColor = forward ? NextColor(currentColor) :
- PrevColor(currentColor);
- }
-
- break;
- }
- }
- }
-
- colorButton->ChangeText(colorString());
- depiction->painter->SetColors(palette[currentColor], white);
- break;
-
- case brusht:
- if (!strcmp(text, no_brush_str)) /* currently no brush */
- {
- brushset = true;
- currentBrush = forward ? solidb : numbrush - 1;
- }
- else /* find the current brush */
- {
- for (i = 0; i < numbrush; i++)
- {
- if (!strcmp(brushst[i], text))
- {
- if ((forward && i == numbrush - 1) ||
- (!forward && i == solidb))
- /* change to no brush */
- {
- currentBrush = default_brush;
- brushset = false;
- }
- else
- {
- currentBrush = forward ? NextBrush(currentBrush) :
- PrevBrush(currentBrush);
- }
-
- break;
- }
- }
- }
-
- brushButton->ChangeText(brushString());
- depiction->painter->SetBrush(brushes[currentBrush]);
- break;
-
- }
-
- depiction->allow();
- DrawDep();
- }
-
- CycleParam::CycleParam(char* btext, char* mtext, DrawView* d, AttType t)
- /**
- a button with text inside and text outside.
- Need to know the drawview to call routines when the button is pressed.
- Pass AttType to drawview so it knows which button we are
- **/
- {
- dv = d;
- text = mtext;
- type = t;
- message = new Message(strdup(text));
- button = new CycleButton(btext, new ButtonState(), this);
-
- Insert(button);
- Insert(new HGlue);
- Insert(message);
- }
-
- void CycleParam::ChangeText (char* t)
- /* change the text *outside* the button */
- {
- Remove(message);
- delete message;
- text = t;
- message = new Message(strdup(t));
- Insert(message);
- Change(message);
- }
-
- void CycleParam::reset()
- /* reset the attribute the button represents */
- {
- dv->reset(type);
- }
-
- void CycleParam::cycle(boolean forward)
- /* cycle the attribute the button represents */
- {
- dv->cycle(text, forward, type);
- }
-
- CycleButton::CycleButton (char* s, ButtonState* b, CycleParam* p) : (s, b, -1)
- /* the button for a cycle param */
- {
- cp = p;
- }
-
- void CycleButton::Handle (Event& e)
- /**
- right mouse button: cycle forward
- middle mouse button: reset
- left moues button: cycle backward
- **/
- {
- if (e.eventType == DownEvent)
- {
- switch (e.button)
- {
- case RIGHTMOUSE:
- cp->cycle(true);
- break;
- case MIDDLEMOUSE:
- cp->reset();
- break;
- case LEFTMOUSE:
- cp->cycle(false);
- break;
- }
- }
- }
-
- Depiction::Depiction() : ()
- /* the drawview sets most of the variables */
- {
- okaytodraw = true;
- }
-
- void Depiction::Draw()
- {
- if (okaytodraw && canvas != nil)
- {
- switch(currShape)
- {
- case circle:
- painter->Circle(canvas, shape->width/2, shape->height/2,
- min(shape->width, shape->height) / 4);
- break;
- case oval:
- painter->Ellipse(canvas, shape->width/2, shape->height/2,
- shape->width/4, shape->height/4);
- break;
- case npoint:
- painter->Point(canvas, shape->width/2, shape->height/2);
- break;
- case diamond:
- {
- Coord x[4], y[4];
-
- x[0] = shape->width/4; y[0] = shape->height/2;
- x[1] = shape->width/2; y[1] = shape->height/4;
- x[2] = 3 * shape->width/4; y[2] = shape->height/2;
- x[3] = shape->width/2; y[3] = 3 * shape->height/4;
- painter->Polygon(canvas, x, y, 4);
- }
- break;
- case double_box:
- painter->Rect(canvas, shape->width/4, shape->height/4,
- 3 * shape->width/4, 3 * shape->height/4);
- painter->Rect(canvas, shape->width/4 + db_margin,
- shape->height/4 + db_margin,
- 3 * shape->width/4 - db_margin,
- 3 * shape->height/4 - db_margin);
- break;
- case rectangle:
- painter->Rect(canvas, shape->width/4, shape->height/4,
- 3 * shape->width/4, 3 * shape->height/4);
- break;
- case line:
- break;
- }
- }
- }
-
- void Depiction::Redraw(Coord a, Coord b, Coord c, Coord d)
- {
- Draw();
- }
-